package com.next.aap.server.controller;

import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.next.aap.client.AssemblyConstituencyWeb;
import com.next.aap.client.DistrictWeb;
import com.next.aap.client.StateDto;
import com.next.core.exception.AppException;

@Controller
public class LocationController extends BaseController{

	
	@RequestMapping(value="/state/getall", method = RequestMethod.GET)
    @ResponseBody
    public String getAllStates(HttpServletResponse httpResponse){
		return locationCache.getAllStates();
	}
	
	@RequestMapping(value="/state/save", method = RequestMethod.POST)
    @ResponseBody
    public StateDto saveState(@RequestBody StateDto stateDto) throws AppException{
		return appService.saveState(stateDto);
	}
	
	@RequestMapping(value="/districtofstate/get/{stateId}", method = RequestMethod.GET)
    @ResponseBody
    public String getDistrictOfState(HttpServletResponse httpResponse,@PathVariable long stateId){
		return locationCache.getAllDistrictOfState(stateId);
	}
	
	@RequestMapping(value="/district/save", method = RequestMethod.POST)
    @ResponseBody
    public DistrictWeb saveDistrict(@RequestBody DistrictWeb districtWeb) throws AppException{
		return appService.saveDistrict(districtWeb);
	}
	@RequestMapping(value="/districts/save", method = RequestMethod.POST)
    @ResponseBody
    public List<DistrictWeb> saveDistricts(@RequestBody DistrictWeb[] districtWeb) throws AppException{
		return appService.saveDistricts(Arrays.asList(districtWeb));
	}

	@RequestMapping(value="/acofdistrict/get/{districtId}", method = RequestMethod.GET)
    @ResponseBody
    public String getAllAssemblyConstituenciesOfDistrict(HttpServletResponse httpResponse,@PathVariable long districtId){
		return locationCache.getAllAssemblyConstituenciesOfDistrict(districtId);
	}
	
	@RequestMapping(value="/acofstate/get/{stateId}", method = RequestMethod.GET)
    @ResponseBody
    public String getAllAssemblyConstituenciesOfState(HttpServletResponse httpResponse,@PathVariable long stateId){
		return locationCache.getAllAssemblyConstituenciesOfState(stateId);
	}
	
	@RequestMapping(value="/acofstate/getformanifesto/{stateId}", method = RequestMethod.GET)
    @ResponseBody
    public String getAllAssemblyConstituenciesOfStateForManifesto(HttpServletResponse httpResponse,@PathVariable long stateId){
		return manifestoCache.getAcWithManifesto();
	}

	@RequestMapping(value="/acofstate/getforcandidate/{stateId}", method = RequestMethod.GET)
    @ResponseBody
    public String getAllAssemblyConstituenciesOfStateForCandidate(HttpServletResponse httpResponse,@PathVariable long stateId){
		return candidateCache.getAcWithCandidates();
	}

	@RequestMapping(value="/ac/save", method = RequestMethod.POST)
    @ResponseBody
    public AssemblyConstituencyWeb saveAssemblyConstituency(@RequestBody AssemblyConstituencyWeb assemblyConstituencyWeb) throws AppException{
		return appService.saveAssemblyConstituency(assemblyConstituencyWeb);
	}
	
	@RequestMapping(value="/acs/save", method = RequestMethod.POST)
    @ResponseBody
    public List<AssemblyConstituencyWeb> saveAssemblyConstituency(@RequestBody AssemblyConstituencyWeb[] assemblyConstituencyWeb) throws AppException{
		return appService.saveAssemblyConstituencies(Arrays.asList(assemblyConstituencyWeb));
	}

}
